import Vue from 'vue'
import Router from 'vue-router'
import axios from 'axios'
Vue.use(Router)

import Err from '../pages/404.vue'
import Login from '../pages/login.vue'
import Index from '../pages/index.vue'
// import Home from '../components/home.vue'
const routes=[
    {
        path:'/iadmin',
        redirect:'/iadmin/login'
    },
    {
        path:'/iadmin/index',
        component:Index
    },
    {
        path:'/iadmin/err',
        component:Err
    },
    {
        path:'/iadmin/login',
        component:Login
    }
]

var router = new Router({
    mode:'history',
    routes
})

router.beforeEach((to, from, next)=>{
    if(to.path != '/iadmin/login'){
        axios.post('/admin/islogin').then((res) =>{
            if(res.data.ret){
                console.log(to)
                next()
            }else{
                next('/iadmin/login')
            }
        })
    }else{
        next()
    }
   
})

export default router;